package actions;

import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.DegreeForm;
import forms.StudentForm;
import model.StudentModel;

public class StudentConfirmationAction extends Action {
	
	private static final boolean DEBUG = true;
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
		
		StudentForm sform = (StudentForm)request.getSession().getAttribute("sform");
		Vector<DegreeForm> degrees = (Vector<DegreeForm>)request.getSession().getAttribute("degrees");
		
		String user = request.getUserPrincipal().getName();
			
		if (DEBUG) {
			System.err.println("StudentConfirmationAction: user(" + user +")");
		}
		
		StudentModel.insertStudent(user, sform, degrees);
		
		return mapping.findForward("success");
	}
}
